package com.wc.codeforces.排序.Farmer_John_s_Card_Game;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/4 19:05
 * @description
 * https://codeforces.com/contest/2060/problem/B
 */
public class Main {
    /**
     * 思路：
     * 先按照 行排序
     * 然后按照第一个数字 排序
     * 保证是有序的, 得出答案
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2010;
    static int[][] f = new int[N][N];
    static int n, m;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            m = sc.nextInt();
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    f[i][j] = sc.nextInt();
                }
                Arrays.sort(f[i], 1, m + 1);
                f[i][0] = i;
            }
            Arrays.sort(f, 1, n + 1, Comparator.comparing(o -> o[1]));
            int res = 0, id = 0;
            for (int j = 1; j <= m; j++) {
                for (int i = 1; i <= n; i++) {
                    if (f[i][j] != id++) {
                        res = -1;
                        break;
                    }
                }
                if (res == -1) break;
            }
            if (res == -1) out.println(res);
            else {
                for (int i = 1; i <= n; i++) out.print(f[i][0] + " ");
                out.println();
            }
        }
        out.flush();
    }
}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
